package com.dingli.shop.controller.controller;

import com.dingli.shop.biz.MenusBiz;
import com.dingli.shop.po.MenusVO;
import com.dingli.shop.vo.JsonVo;
import com.dingli.shop.vo.Meta;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@CrossOrigin
@Controller
public class MenusController {
    @Autowired
    private MenusBiz menusBiz;

    @GetMapping("/menus")

    public @ResponseBody
    JsonVo menus() {
        List<MenusVO> menusVO =  menusBiz.findMenus();
        Meta meta = new Meta();
        if (menusVO == null) {
            meta.setMsg("没有找到菜单");
            meta.setStatus(400);
        } else {
            meta.setMsg("获取菜单列表成功");
            meta.setStatus(200);
        }
        JsonVo jsonVo = new JsonVo();
        jsonVo.setData(menusVO);
        jsonVo.setMeta(meta);
        return jsonVo;
    }

}
